<?php

class Csponsors extends Zend_Db_Table
{

    protected $product;

    protected $_name;

    protected $_primary;

    public function _setup()
    {

        $this->_name=R_PRE."sponsors";

        $this->_primary="pid";

        parent::_setup();
    }

    public function createsponsors($data)
    {

        $pid=$this->insert($data);

        return $pid;
    }

    public function getAllsponsors($where='')
    {

        $db=$this->getAdapter();

        $select = $db->select();

        $select->from($this->_name,'*');

        if($where!='')
        {

            $select->where($where);
        }

        $select->order("pid ASC");

        return $db->fetchAll($select);

    }


	/* $data=array(
					'0'=>array('pid'=>'1','itemid'=>'1','min_counts'=>'dffs'),
					'1'=>array('pid'=>'2','itemid'=>'2','min_counts'=>'2323')
				   )
	表单中attachmentid为空的是新增附件(执行插入操作), 不为空的则为之前的附件(执行修改操作)
	*/

    public function editsponsors($pid, $thisArray)
    {

        $db=$this->getAdapter();

        $where=$db->quoteInto('pid = ?', $pid);

        $db->update($this->_name, $thisArray, $where);

    }

    public function getDetail($pid)
    {

        $db=$this->getAdapter();

        $select = $db->select();

        $select->from($this->_name,'*');

        $select->where('pid = ? ',$pid);

        return $db->fetchAll($select);

    }

    public function delsponsors($pidArray)
    {

        $db=$this->getAdapter();

        $pidString=join(',',$pidArray);

        $result=$db->query("DELETE FROM $this->_name WHERE pid IN ($pidString)");

        return $result;

    }

    public function getsponsorsIN($itemidArray)
    {

        $db=$this->getAdapter();
        //$itemidString=join(',',$itemidArray);
        $itemidString=$itemidArray;

        if ($itemidString)
        {
            $result=$db->fetchAll("SELECT * FROM $this->_name WHERE pid IN ($itemidString)");
        }

        return $result;
    }

    public function delsponsorsByItemid($itemidArray)
    {

        $db=$this->getAdapter();

        $itemidString=join(',',$itemidArray);

        $result=$db->query("DELETE FROM $this->_name WHERE itemid IN ($itemidString)");

        return $result;
    }

    public function getItemsByItemid($itemid,$amounts)
    {
        $db=$this->getAdapter();
        return $db->fetchAll("SELECT * FROM $this->_name WHERE min_counts<='$amounts' AND itemid = '$itemid'");
    }
}
?>